//控制层：baseController
app.controller("baseController",function ($scope) {
    //引入分页的配置对象属性
    $scope.reload = true;
    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 100,
        itemsPerPage: 5,
        pagesLength: 15,
        perPageOptions: [5, 10, 15, 20, 30, 40, 50],
        onChange: function(){
            if (!$scope.reload){
                return;
            }
            $scope.search();
            $scope.reload = false;
            setTimeout(function () {
                $scope.reload = true;
            },200)
        }
    };

    //定义用于存放选中项ID的数组
    $scope.selectIds = [];
    //定义选中复选框的操作
    $scope.selectOne = function (event,id) {
        if (event.target.checked) //当选中复选框就把对应的ID放入数组中
            $scope.selectIds.push(id);
        else {
            var index = $scope.selectIds.indexOf(id);//得到此ID在数组中的下标
            if (index != -1)
                $scope.selectIds.splice(index,1);//根据下标移除数组中的元素
        }
    };
    //全选、反选
    $scope.selectAll = function (event,list) {
        if (event.target.checked) {
            //遍历从后台获取的列表
            angular.forEach(list,function (item) {
                item.checked = true;//选中所有复选框
                $scope.selectIds.push(item.id)//把选中的品牌ID放入数组中
            })
        }else {
            angular.forEach(list,function (item){
                item.checked = false;//取消所有复选框
                $scope.selectIds = [];//清空数组
            })
        }
    };

    //定义转换日期格式的方法
    $scope.getTime = function (time) {
        var date = new Date(time);
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        return year+"-"+month+"-"+day+"　"+hour+":"+minute+":"+second;
    };


});